//
//  SISSTitleView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/10.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSTitleView.h"

@interface SISSTitleView ()

/* <#Annotation#> */
@property (weak, nonatomic) UILabel *titleLabel;

@end
@implementation SISSTitleView

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    self.backgroundColor = [UIColor groupTableViewBackgroundColor];

    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"";
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = SECONDARY_TEXT_COLOR;
    titleLabel.numberOfLines = 0;
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(16);
        make.right.equalTo(self).offset(-16);
    }];
}

- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    self.titleLabel.textColor = titleColor;
}

- (void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    
    if (titleStr.length == 0) return;
    
    if ([[titleStr substringToIndex:1] isEqualToString:@"*"]) {
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:titleStr];
        [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,1)];
        self.titleLabel.attributedText = attributedStr;
    } else {
        self.titleLabel.text = titleStr;
    }
}

@end
